<?php
namespace app\modules\weixin\controllers;

use app\common\service\BaseService;
use app\common\service\UrlService;
use app\common\service\weixin\RequestService;
use phpDocumentor\Reflection\DocBlock\Tags\Var_;

class MenuController extends BaseService
{
    public function actionSet()
    {
        $menu = [
            "button" =>[
                [
                    "name" => "商城",
                    "type" => "view",
                    "url" => UrlService::buildMUrl("default/index"),
                ],
                [
                    "name" => "我",
                    "type" => "view",
                    "url" => UrlService::buildMUrl("/user/index"),
                 ],
            ],
        ];

        $config = \Yii::$app->params['weixin'];
        RequestService::setConfig( $config['appid'],$config['token'],$config['appsecret'] );
        $access_token = RequestService::getAccessToken();
        if( $access_token ){
            $url = "menu/create?access_token=".$access_token;
            $ret = RequestService::send( $url,json_encode( $menu,JSON_UNESCAPED_UNICODE ),"POST" );
            var_dump( $ret );
        }
    }
}